/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       postprocess.cpp
 * Author:     twoja stara
 * Created on: 2009-09-17
 *
 **********************************************************************************************************************/

#include "postprocess.h"

namespace mGameEngine
{
namespace Graphics
{

PostProcess::PostProcess(const Texture *input, RenderTarget *output) :
    _input(input), _output(output), 
    _enabled(true)
{
}

PostProcess::~PostProcess()
{
}

void PostProcess::_passUnprocessed() const
{
    // create and compile GPU program
    static GPUProgram gpuProgram(
#include "postprocess.vert"
        ,
#include "postprocess.frag"
        , true);

    // no input or output
    if(!_input || !_output)
    {
        return;
    }

    // use program
    gpuProgram.use();
    gpuProgram.setTexture("texture", _input, 0);

    // render image
    _output->beginRendering();

    glDisable(GL_DEPTH_TEST);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex2fv(Vector2(0.0f, 0.0f));
        glVertex2fv(Vector2(1.0f, 0.0f));
        glVertex2fv(Vector2(0.0f, 1.0f));
        glVertex2fv(Vector2(1.0f, 1.0f));
    glEnd();

    _output->endRendering();
}

}
}

